﻿using UnityEngine;

namespace State
{
    /// <summary>
    /// 拥有状态的游戏物体
    /// </summary>
    public abstract class BaseContextBase : MonoBehaviour
    {
        public StateBase State;

        #region 工具方法
        /// <summary>
        /// 检查当前的状态是否是某状态
        /// </summary>
        public bool CheckState<T>() where T : StateBase
        {
            return State != null && State is T;
        }

        /// <summary>
        /// 尝试获取当前的状态具体对象
        /// </summary>
        public bool TryGetState<T>(out T state) where T : StateBase
        {
            if (CheckState<T>())
            {
                state = State as T;
                return true;
            }
            state = default;
            return false;
        }
        #endregion

#if UNITY_EDITOR
        #region 扩展编辑器用
        [HideInInspector]
        public int childTypeSelectIndex;
        #endregion
#endif
    }
}